home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 6.5 KB | 227 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLMacOS.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifdef FW_BUILD_MAC
-
- #ifndef SLMACOS_H
- #include "SLMacOS.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwtoolbx
- #endif
-
- //========================================================================================
- // Mac OS Utlities
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_PrivMacBuildWindowRegions
- //----------------------------------------------------------------------------------------
- // Calculate window size including structure region (i.e. title bar). To do this we need,
- // if the window isn't shown, to force the window to compute its structure region by
- // calling its defproc. If build is false, set the regions back to empty regions, so
- // as not to confuse the window manager. Return the previous state of the regions.
-
- typedef pascal long(*WDefProcType)(short varCode,
- WindowPtr theWindow,
- short message,
- long param);
-
- typedef WDefProcType *WDefProcTypeHandle;
-
- static Handle MacGetAndLoadWDefProc(Handle windowDefProc)
- {
- if ((*windowDefProc)) // if Master Ptr is NULL => resource is purged
- return windowDefProc;
- else
- {
- FW_SOMEnvironment ev;
- FW_CAcquireCFMResourceAccess qr(ev);
- ::LoadResource(windowDefProc);
- if (::ResError() == noErr) // only return it if the LoadResource worked
- return windowDefProc;
- else
- return NULL;
- }
- }
-
- FW_Boolean FW_PrivMacBuildWindowRegions(WindowPtr windowPtr, FW_Boolean build, FW_PlatformError* error)
- {
- FW_ERR_TRY
- {
- FW_ASSERT(windowPtr != NULL);
-
- WindowRecord &theWindowRecord = *((WindowPeek)windowPtr);
-
- // The regions are considered to be built if either:
- // a) the window is shown; or
- // b) the structure rgn is not empty.
-
- if (theWindowRecord.visible || !::EmptyRgn(theWindowRecord.strucRgn))
- {
- if ((build != true) && !theWindowRecord.visible)
- {
- ::SetEmptyRgn(theWindowRecord.strucRgn);
- ::SetEmptyRgn(theWindowRecord.contRgn);
- }
- return true;
- }
- else
- {
- if (build == true)
- {
- WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)MacGetAndLoadWDefProc(theWindowRecord.windowDefProc);
- if (wDefProc)
- {
- SignedByte savedState = ::HGetState((Handle)wDefProc);
- ::HLock((Handle)wDefProc);
- // WindowDefUPP windowDefUPP = NewWindowDefProc(*wDefProc);
- WindowDefUPP windowDefUPP = (WindowDefUPP) NewRoutineDescriptor((ProcPtr)(*wDefProc), uppWindowDefProcInfo, ((ISAType) kM68kISA));
- if (windowDefUPP == NULL)
- *error = FW_xMemoryExhausted;
- else
- {
- CallUniversalProc(windowDefUPP, uppWindowDefProcInfo, ::GetWVariant(windowPtr), windowPtr, wCalcRgns, 0);
- DisposeRoutineDescriptor(windowDefUPP);
- ::HSetState((Handle)wDefProc, savedState);
- }
- }
- }
- return false;
- }
- }
- FW_ERR_CATCH
-
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MacGetMaxIntersectedDevice
- //----------------------------------------------------------------------------------------
-
- GDHandle FW_MacGetMaxIntersectedDevice(WindowPtr windowPtr, FW_SRect& screenRect, FW_PlatformError* error)
- {
- GDHandle maxSectGD = NULL;
-
- FW_ERR_TRY
- {
- FW_ASSERT(windowPtr != NULL);
-
- FW_Boolean rgnsWereBuilt = FW_PrivMacBuildWindowRegions(windowPtr, true, error);
- if (*error)
- return NULL;
-
- Rect globalStrucRect = (*(((WindowPeek)windowPtr)->strucRgn))->rgnBBox;
- FW_PrivMacBuildWindowRegions(windowPtr, rgnsWereBuilt, error);
- if (*error)
- return NULL;
-
- long maxSectArea = 0;
- Rect moveBounds = (*(GetGrayRgn()))->rgnBBox;
- InsetRect(&moveBounds, 4, 4);
-
- GDHandle aGDHandle = ::GetDeviceList();
- maxSectGD = ::GetMainDevice(); // Set as best choice default
- while (aGDHandle)
- { // calc which scrn intersects largest part of window
- if (::TestDeviceAttribute(aGDHandle, screenDevice) && ::TestDeviceAttribute(aGDHandle, screenActive))
- {
- Rect aGDScreenRect = (*aGDHandle)->gdRect;
- Rect gdSectRect;
- Rect dontCare;
- if (::SectRect(&aGDScreenRect, &moveBounds, &dontCare) && ::SectRect(&globalStrucRect, &aGDScreenRect, &gdSectRect))
- {
- long sectArea = (gdSectRect.bottom - gdSectRect.top) * (gdSectRect.right - gdSectRect.left);
- if (sectArea > maxSectArea) // do we have a new winner?
- {
- maxSectArea = sectArea;
- maxSectGD = aGDHandle;
- }
- }
- }
- aGDHandle = ::GetNextDevice(aGDHandle);
- }
-
- FW_CRect* castedRect = (FW_CRect*)&screenRect;
-
- if (maxSectGD != ::GetMainDevice())
- *castedRect = (*maxSectGD)->gdRect;
- else
- {
- // Account for menu bar on the main screen.
- // Don't just assume that its at the top of
- // the screen!
- Rect gdRect = (*maxSectGD)->gdRect;
-
- RgnHandle tempRgn = ::NewRgn();
- if (tempRgn == NULL)
- {
- *error = FW_xMemoryExhausted;
- return NULL;
- }
- ::RectRgn(tempRgn, &gdRect); // main screen with menubar
- ::SectRgn(tempRgn, GetGrayRgn(), tempRgn); // GetGrayRgn == desktop rgn w/o menubar
- *castedRect = (*tempRgn)->rgnBBox; // => main screen w/o menubar
- ::DisposeRgn(tempRgn);
- }
- }
- FW_ERR_CATCH
-
- return maxSectGD;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MacZoomWindow:
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError FW_MacZoomWindow(WindowPtr windowPtr, FW_Boolean zoomIn)
- {
- // No try block necessary - Do not throw
- GrafPtr curGrafPort;
- ::GetPort(&curGrafPort);
- ::SetPort(windowPtr); // The ROM requires that thePort be the window being zoomed.
-
- ::ClipRect(&windowPtr->portRect);
- ::EraseRect(&windowPtr->portRect);
- ::ZoomWindow(windowPtr, zoomIn ? inZoomIn : inZoomOut, true);
-
- ::SetPort(curGrafPort);
-
- return FW_xNoError;
- }
-
- #endif
-